package com.elh.jpa.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "usertest")
public class User implements Serializable {

    private static final String CUSTOM_ID_GENERATOR_NAME = "customId";
    private static final String CUSTOM_ID_GENERATOR = "com.elh.jpa.dao.CustomIDGenerator";

    @Id
    @Column(length = 64)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = CUSTOM_ID_GENERATOR_NAME)
    @GenericGenerator(name = CUSTOM_ID_GENERATOR_NAME, strategy = CUSTOM_ID_GENERATOR)
    private String id;
    private String name;
    private Long age;

    @CreatedDate
    @Column(nullable = false, updatable = false)
    protected LocalDateTime createdDate;

    @LastModifiedDate
    protected LocalDateTime lastModifiedDate;

    @CreatedDate
    private Date date;

    public User(String sname, long sage) {
        this.name = sname;
        this.age = sage;
    }
}